import java.util.Random;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Random random = new Random();
        int n = random.nextInt(100);
        System.out.println("随机数"+n);
        Scanner scan = new Scanner(System.in);

        while (true) {
            System.out.println("输入你要猜的数字：");
            int num = scan.nextInt();
            if (num < n) {
                System.out.println("猜小了！");
            } else if (num > n) {
                System.out.println("猜大了！");
            } else {
                System.out.println("猜对了！");
                break;
            }
        }
    }
    //Java 当中 如何生成一个简单的随机数
    public static void main10(String[] args) {
        Random random = new Random();
        //int n = random.nextInt(100); [0,100)
        //int n = random.nextInt(100)+1;//[1,101)
        // int n = random.nextInt(51)+50;//[0,49] + 50
        int n = random.nextInt(102);//[0,49] + 50
        System.out.println(n);

        //java生成随机数的另一个类:　　Math.random(); todo:自主学习这个方法生成随机数！
    }
    public static void main9(String[] args) {
        Scanner scan = new Scanner(System.in);
        /*
        while (scan.hasNextInt()) {
            System.out.println("输入你的年龄：");
            int age = scan.nextInt();
            System.out.println("年龄：" + age);
        }
        */
        while (scan.hasNextLine()){
            System.out.println("输入你的姓名：");
            String name = scan.nextLine();
            System.out.println("姓名："+name);
        }
        //在cmd命令行窗口，结束的时候 使用ctr+z  IDEA上是CTR+D
    }
    //从键盘输入
    public static void main8(String[] args) {
        // 打出Scanner,打出之后鼠标挪到Scanner上，然后按alt+回车即可导入对应的util的包。
        //ctrl+鼠标左键即可跳到对应的java文件中去
        Scanner scan = new Scanner(System.in);//System.in代表从键盘输入
        System.out.println("输入你的姓名：");
        String name = scan.nextLine();
        System.out.println("姓名："+name);
        System.out.println("输入你的年龄：");
        int age = scan.nextInt();
        System.out.println("年龄："+age);
        System.out.println("输入你的工资：");
        float money = scan.nextFloat();
        System.out.println("工资："+money);
        scan.close();//资源用完要进行关闭
    }
    public static void main7(String[] args) {
        System.out.println(10);//输出且换行
        System.out.print("不换行");
        System.out.printf("%s","这是格式化输出！");
    }
    public static void main6(String[] args) {
        //for循环的死循环写法
         /*for(;;){
            System.out.println("dsfafa");
        }*/

        //至少会执行一次 所以一般不怎么使用它
        int num = 1;
        do {
            System.out.println(num);
            num++;
        } while (num <= 0);
    }
    public static void main5(String[] args) {
        //找到1~100之间的既能被3整除也能被5整除的所有数字
        for(int i = 1;i<=100;){
            if(i%15 != 0){
                i++;
                continue;
            }
            System.out.println(i);
            i++;
        }
    }
    public static void main4(String[] args) {
        //5的阶层和
        int i = 1;
        int sum = 0;
        while(i<=5){
            int ret = 1;
            int j = 1;
            while(j<=i){
                ret*=j;
                j++;
            }
            sum+=ret;
            i++;
        }
        System.out.println(sum);
    }
    public static void main3(String[] args) {
        //1-100的和
        //1-100的奇数和
        //1-100的偶数和
        //1-10
        int i = 1;
        int sum = 0;
        int sum1 = 0;
        while (i <= 100) {
           if(i%2==0)sum+=i;
           if(i%2!=0)sum1+=i;
           i++;
        }
        System.out.println(sum+sum1);

        System.out.println(sum);
        System.out.println(sum1);
    }
    public static void main2(String[] args) {
        //不能做switch的参数的数据类型是哪些？
//        long,float,double,boolean都不可以
        String  a = "hello";

        long b = 2;
        switch (a) {
            case "abc":
                System.out.println("two");
                break;
            case "hello":
                System.out.println("one");
                break;
            default:
                System.out.println("没有匹配！");
                break;
        }
    }
    public static void main1(String[] args) {
        int a = 2;
        switch (a) {
            case 2:
                System.out.println("two");
                break;
            case 1:
                System.out.println("one");
                break;
            default:
                System.out.println("没有匹配！");
                break;
        }
    }
}
